<!doctype html>
<html lang="zh" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>HDFS Web Management</title>
    <link rel="ICON" href="img/icon.png">
    <link rel="stylesheet" href="css/css-loader.css">
    <link rel="stylesheet" type="text/css" href="css/default.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/iziModal.min.css">
    <link rel="stylesheet" href="css/sweetalert.css">
    <link rel="stylesheet" href="css/jquery.plupload.queue.css">

    <style type="text/css">
        .htmleaf-header{margin-bottom: 15px;font-family: "Segoe UI", "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", "FontAwesome", sans-serif;}
        .htmleaf-icon{color: #fff;}
    </style>

    <style>
        @media (max-width: 480px){
            .content {
                width: 100%;
            }
        }
        @media (min-width: 481px) and (max-width: 767px){
            .content {
                width: 470px;
            }
        }
        @media (min-width: 768px) and (max-width: 991px){
            .content {
                width: 750px;
            }
        }
        @media (min-width: 992px) and (max-width: 1199px){
            .content {
                width: 970px;
            }
        }
        @media (min-width: 1200px) and (max-width: 1499px){
            .content {
                width: 1100px;
            }
        }
        @media (min-width: 1500px) and (max-width: 1799px){
            .content {
                width: 1400px;
            }
        }
        @media (min-width: 1800px){
            .content {
                width: 1700px;
            }
        }
        .content{
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            margin: 0 auto;
        }
    </style>
<body>
<div class="htmleaf-container">
    <header class="htmleaf-header bgcolor-12">
        <h1>校园云学习平台---云存储平台 <span>Based on HDFS API(Java)</span></h1>
        <div class="htmleaf-links">
            <form th:action="@{./logout}" method="post" id="logoutForm">
                <a class="htmleaf-icon icon-htmleaf-home-outline" href="#" title="主页" ><span> 主页</span></a>
                <a class="htmleaf-icon icon-htmleaf-arrow-forward-outline" title="返回" onclick="$('#logoutForm').submit()"><span>退出</span></a>
            </span>
            </form>
        </div>
    </header>

    <!-- Clock Animation -->
    <div class="loader loader-clock is-active" id="animation_clock"></div>

    <!-- Json文件树 -->
    <div class="content">
        <div class="row">
            <div class="col-sm-12" style="margin-bottom: 10px">
                <h2>云存储空间(Cloud Storage)<br><small>(文件管理)</small></h2>
                <div class="pull-left m-1-10">
                    <span>当前用户:&nbsp;</span><span th:inline="text" id="username" style="font-size: 14px">[[${#httpServletRequest.remoteUser}]]</span>
                </div>
                <div class="pull-right m-l-10">
                    <button class="btn btn-info" id="upload_btn" name="upload_button" type="button" onclick="upload();">上传</button>
                    <button class="btn btn-info" id="folder_btn" name="mkdir_button" type="button" data-toggle="modal" data-target="#MkdirModal" onclick="openModalMkdir(1);">创建文件夹</button>
                    <button class="btn btn-danger" id="delete_btn" name="delete_button" type="button" onclick="deleteDir();">删除文件夹</button>
                </div>
            </div>
        </div>
        <div class="table-responsive">
            <div id="treeview12" class=""></div>
        </div>
        <hr>
    </div>
</div>

<!-- iframe-1 文件管理信息窗口 -->
<div id="modal-custom" class="iziModal">
    <button data-iziModal-close class="icon-close">X</button>
    <header>
        <a href="#" class="active"><h3>文件管理</h3></a>
    </header>
    <section style="padding-top:10px; padding-bottom: 5px">
        文件名：<input id="fileName" type="text" placeholder="文件名" class="form-control" disabled/>
        创建时间：<input type="text" id="fileCreateTime" placeholder="创建时间" class="form-control" disabled/>
        文件大小：<input type="text" id="fileSize" placeholder="文件大小" class="form-control" disabled/>
        文件路径：<input type="text" id="filePath" placeholder="文件路径" class="form-control" disabled/>
    </section>
    <div id="modal-custom-btn-group" style="width: 600px; padding: 0 30px 30px; margin: auto">
        <div id="btn-group" class="center-block" style="width: 356px">
            <button id="delete_file_btn" name="delFile" class="btn btn-danger" type="button" style="width: 68px" onclick="delete_FileFunc()">删除</button>
            <button id="rename_file_btn" name="renameFile" class="btn btn-warning" style="width: 68px" type="button" data-toggle="modal" data-target="#RenameModal" onclick="renameFileModal();">重命名</button>
            <button id="copy_file_btn" name="copyFile" class="btn btn-info" style="width: 68px" type="button" onclick="copyFile();">复制</button>
            <button id="move_file_btn" name="moveFile" class="btn btn-info" style="width: 68px" type="button">移动</button>
            <button id="download_file_btn" name="downFile" class="btn btn-success" style="width: 68px" type="button" onclick="download_Func()">下载</button>
        </div>
    </div>
</div>

<!-- iframe-2 文件夹为空的提示窗口 -->
<div id="modal-empty-folder" class="iziModal">
    <button data-iziModal-close class="icon-close">X</button>
    <header>
        <a href="#" class="active"><h3>文件夹管理</h3></a>
    </header>
    <section style="padding-top:10px; padding-bottom: 5px">
        文件名：<input type="text" id="fileName_1" placeholder="文件名" class="form-control" disabled/>
        文件路径：<input type="text" id="filePath_1" placeholder="文件路径" class="form-control" disabled/>
    </section>
    <div id="modal-btn-group" style="width: 600px; padding: 0 30px 30px; margin: auto">
        <div id="btn-group-1" class="center-block" style="width: 396px">
            <button id="delete_folder_btn" name="delFolder" class="btn btn-danger" onclick="deleteDir($('#filePath_1').val());">删除文件夹</button>
            <button id="upload_btn_1" name="upload_button" class="btn btn-info" type="button" onclick="upload('Folder');">上传文件</button>
            <button id="add_folder_btn" name="addFolder" class="btn btn-success" data-toggle="modal" data-target="#MkdirModal" onclick="openModalMkdir(2);">添加文件夹</button>
            <button id="rename_btr" name="renameFolder" class="btn btn-warning">重命名文件夹</button>
        </div>
    </div>
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header"></div>
            <div id="uploader">你的浏览器不支持本地上传.</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default pull-right" data-dismiss="modal" onclick="window.location.reload();">关闭</button>
                <button type="button" class="btn btn-info pull-left" id="pause_upload" name="pause_upload_btn">暂停上传</button>
                <button type="button" class="btn btn-success pull-left" id="continue_upload" name="continue_upload_btn">继续上传</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<!-- 创建文件夹的提示窗口 -->
<div class="modal fade" id="MkdirModal" tabindex="-1" role="dialog" aria-labelledby="MkdirModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="MkdirModalLabel">创建文件夹</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <p>当前路径:&nbsp;<span id="folder-path"></span></p>
                        <label for="folder-name" class="control-label">文件夹名称:</label>
                        <input type="text" class="form-control" id="folder-name" value="">
            </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="createFolder($('#folder-path').text())">创建</button>
            </div>
        </div>
    </div>
</div>

<!-- 重命名文件的提示窗口 -->
<div class="modal fade" id="RenameModal" tabindex="-1" role="dialog" aria-labelledby="RenameModalLabel">
    <div class="modal-dialog" role="document" style="background: #ffffff; border-radius: 4px">
        <div class="modal-content" style="border: 0; box-shadow: none">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="RenameModalLabel">重命名文件</h4>
            </div>
        </div>
        <div class="modal-body-rename">
            <form>
                <div class="form-group" style="padding: 15px">
                    <p>当前路径:&nbsp;<span id="oldPath"></span></p>
                    <label for="rename_folder_path" class="control-label">文件夹路径:</label>
                    <input type="text" id="rename_folder_path" class="form-control" disabled>
                    <label for="rename_file_name" class="control-label">文件名:</label>
                    <input type="text" id="rename_file_name" class="form-control" value="">
                    <label for="rename_file_suffix" class="control-label">文件后缀名:</label>
                    <input type="text" id="rename_file_suffix" class="form-control" disabled>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" onclick="renameFile($('#oldPath').text())">重命名</button>
        </div>
    </div>
</div>

<script src="js/jquery.js"></script>
<script src="vendors/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="js/bootstrap-treeview.js"></script>

<script src="js/jquery-ui.min.js"></script>
<script src="js/plupload/plupload.full.min.js"></script>
<script src="js/jquery.ui.plupload.min.js"></script>
<script src="js/jquery.plupload.queue.js"></script>

<script src="js/i18n/zh_CN.js"></script>
<script src="js/iziModal.min.js"></script>
<script src="js/sweetalert.min.js"></script>


<script type="text/javascript">
    // 上传插件配置列表
    var pluploadQueue_setting = {
        // General settings
        runtimes : 'html5,flash,silverlight,html4',
        url : "../upload_file",

        chunk_size : '10mb',

        filters : {
            max_file_size : '1000mb',
            mime_types: [
                {title : "Image files", extensions : "jpg,gif,png"},
                {title : "Zip files", extensions : "zip,rar"},
                {title : "Video files", extensions : "flv,mp4,avi,mpg,wmv"}
            ]
        },

        headers : { folder_path : "/"},

        max_retries : 3,

        // Resize images on clientside if we can
        resize : {width : 200, height : 200, quality : 90, crop: true },

        // Rename files by clicking on their titles
        rename: true,

        // Sort files
        sortable: true,

        // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
        dragdrop: true,

        // Flash settings
        flash_swf_url : 'js/Moxie.swf',

        // Silverlight settings
        silverlight_xap_url : 'js/Moxie.xap'
    }

    $(document).ready(function () {
        $("#continue_upload").hide();
    });
    
    //初始化
    $(function () {
        init_uploader("/");
    });

    function init_uploader(path) {
        pluploadQueue_setting.headers.folder_path = path;
        //plupload上传队列
        var uploader = $("#uploader").pluploadQueue(pluploadQueue_setting);

        $("#pause_upload").on('click', function () {
            $("#continue_upload").show();
            uploader.stop();
        });

        $("#continue_upload").on('click', function () {
            $("#continue_upload").hide();
            uploader.start();
        });
    }

    //初始化获取json
    getJson();

    //初始化两种iframe
    function init_iframe(){
        //初始化iframe1
        $("#modal-custom").iziModal({
            overlayClose: false,
            width: 600,
            autoOpen: false,
            overlayColor: 'rgba(0, 0, 0, 0.6)',
            onOpened: function() {
                console.log('onOpened');
            },
            onClosed: function() {
                console.log('onClosed');
            }
        });

        //初始化iframe2
        $("#modal-empty-folder").iziModal({
            overlayClose: false,
            width: 600,
            autoOpen: false,
            overlayColor: 'rgba(0, 0, 0, 0.6)',
            onOpened: function() {
                console.log('onOpened');
            },
            onClosed: function() {
                console.log('onClosed');
            }
        });
    }

    //关闭动画
    function closeDisplay() {
        $('#animation_clock').fadeOut(1000);
    }

    //最后一次触发节点Id
    var lastSelectedNodeId = null;
    //最后一次触发时间
    var lastSelectTime = null;
    //初始化json
    var json = [];
    //初始化文件夹路径
    var path = null;

    //Ajax请求
    function getJson() {
        json = [];

        //ajax获取数据
        $.ajax({
            type:"GET",
            url:"get_allFolder",
            success: function (data, Time) {
                console.log(Time);
                json.push(data);
                console.log(JSON.parse(json[0]).json_data);
                closeDisplay();
                init_iframe();
                init_tree_view(JSON.parse(json[0]).json_data);
                setAllNodeClose();
                customDblClickFun();
            },
            error: function (xhr, status, error) {
                console.log("Error Request");
                closeDisplay();
            }
        })
    }

    //初始化树
    function init_tree_view(data) {
        $('#treeview12').treeview({
            color: "#428bca",
            expandIcon: "glyphicon glyphicon-stop",
            collapseIcon: "glyphicon glyphicon-unchecked",
            nodeIcon: "glyphicon glyphicon-file",
            showTags: true,
            level:1,
            highlightSearchResults: true,
            data: data
        });
    }

    //设置默认所有根节点下的节点合上
    function setAllNodeClose(){
        $('#treeview12').treeview('collapseAll', {
            silent: true
        });
    }

    //自定义双击触发方法
    function customDoubleClickBussiness(data){
        $('#treeview12').treeview('toggleNodeExpanded', [ data.nodeId, { silent: true } ]);
    }

    //点击事件
    function clickNode(event, data){
        if (lastSelectTime || lastSelectedNodeId){
            var time = new Date().getTime();
            var t = time - lastSelectTime;
            if (lastSelectedNodeId == data.nodeId && t < 300){
                customDoubleClickBussiness(data);
            }
        }
        lastSelectedNodeId = data.nodeId;
        lastSelectTime = new Date().getTime();
    }

    //容量计算器
    function storgeTransfer(data) {
        console.log(data.size);
        if (data.size > 1024){
            //比1MB大
            if (data.size >= 1024 && data.size < Math.pow(1024,2)){
                console.log("KB");
                //大于1K小于1M
                var file_size = data.size / Math.pow(1024, 1);
                $('#fileSize').val(file_size.toFixed(2) + "KB");
            }
            else if (data.size >= Math.pow(1024,2) && data.size < Math.pow(1024, 3)){
                console.log("MB");
                //大于1M小于1G
                file_size = data.size / Math.pow(1024, 2);
                $('#fileSize').val(file_size.toFixed(2) + "MB");
            }
            else if (data.size >= Math.pow(1024, 3)){
                console.log("GB");
                //大于1G
                file_size = data.size / Math.pow(1024, 3);
                $('#fileSize').val(file_size.toFixed(2) + "GB");
            }
            else {
                //小于1KB
                $('#fileSize').val(file_size + "B");
            }
        }
        else {
            //比1KB小
            $('#fileSize').val(data.size + "B");
        }
    }

    //iframe填值
    function fill_value(data) {
        $('#fileName').val(data.text);
        $('#fileCreateTime').val(data.date);

        if (typeof(data.size) === "undefined"){
            $('#fileSize').val("");
        }
        else {
            storgeTransfer(data);
        }
        var path = data.path;
        $('#filePath').val(path.replace("hdfs://127.0.0.1:9000","").replace("hdfs://192.168.31.53:9000", ""));
    }

    //自定义双击事件
    function customDblClickFun() {
        $('#treeview12').on('nodeSelected', function (event, data) {
            console.log(data);
            // console.log(data.IsEmpty);
            // 文件类型 不属于文件夹且文件夹不是空的
            if(data.type !== "dir" && data.IsEmpty !== true){
                fill_value(data);
                $('#modal-custom').iziModal('open');
            }
            // 文件夹是空的
            else if (data.IsEmpty === true){
                $('#fileName_1').val(data.text);
                path = data.path;
                console.log("/" + $('#username').val());
                $('#filePath_1').val(path.replace("hdfs://192.168.31.53:9000","").replace("hdfs://127.0.0.1:9000", "").replace("/" + $('#username').text(), ""));
                $('#modal-empty-folder').iziModal('open');
            }
            // 文件夹不是空的
            else {
                console.log("/" + $('#username').val());
                $('#folder-path').html(data.path.replace("hdfs://192.168.31.53:9000","").replace("hdfs://127.0.0.1:9000", "").replace("/" + $('#username').text(), ""));
                console.log($('#folder-path').text());
                $('#folder-path').val($('#folder-path').text());
            }
            clickNode(event, data);
        });

        $('#treeview12').on('nodeUnselected', function (event, data) {
            clickNode(event, data);
        });
    }

    //iframe-1的关闭按钮
    $("#modal-custom").on('click', 'header a', function(event) {
        event.preventDefault();
        var index = $(this).index();
        $(this).addClass('active').siblings('a').removeClass('active');
        $(this).parents("div").find("section").eq(index).removeClass('hide').siblings('section').addClass('hide');

        if( $(this).index() === 0 ){
            $("#modal-custom .iziModal-content .icon-close").css('background', '#ddd');
        } else {
            $("#modal-custom .iziModal-content .icon-close").attr('style', '');
        }
    });

    //iframe-2的关闭按钮
    $("#modal-empty-folder").on('click', 'header a', function(event) {
        event.preventDefault();
        $('#folder-path').html("/");
        var index = $(this).index();
        $(this).addClass('active').siblings('a').removeClass('active');
        $(this).parents("div").find("section").eq(index).removeClass('hide').siblings('section').addClass('hide');

        if( $(this).index() === 0 ){
            $("#modal-empty-folder .iziModal-content .icon-close").css('background', '#ddd');
        } else {
            $("#modal-empty-folder .iziModal-content .icon-close").attr('style', '');
        }
    });

    //下载文件
    function download_Func() {
        swal({
            title: "下载",
            text: "你将下载该文件",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "下载",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: false
        },function(isConfirm){
            if (isConfirm) {
                var path = $('#filePath').val();
                $.ajax({
                    url: "download_file",
                    data: "path=" + path,
                    success: function (data) {
                        console.log(data);
                        $("#modal-custom").hide();
                        $(".iziModal-overlay").hide();
                        download_success("下载", function () {});
                        window.location.href = data;
                    },
                    error: function (xhr, status, err) {
                        fail_result("请求服务器", function () {});
                    }
                });
            } else {
                swal("操作失败", "你取消了下载！", "error");
            }
        });
    }

    //删除文件
    function delete_FileFunc() {
        swal({
            title: "提示",
            text: "你将删除该文件",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: false
        },function(isConfirm){
            if (isConfirm) {
                var path = $('#filePath').val();
                $.ajax({
                    url: "delete_file",
                    data: "path=" + path,
                    success: function (data) {
                        console.log(data);
                        if(data){
                            success_result("删除");
                        } else {
                            fail_result('删除', function() {});
                        }
                    },
                    error: function (xhr, status, err) {
                        fail_result("请求服务器", function () {});
                    }
                });
            } else {
                swal("操作失败", "你取消了删除！", "error");
            }
        });
    }

    //创建文件夹弹窗
    function openModalMkdir(arg) {
        var isFolder = null;
        if (arg === 1){
            isFolder = $('#folder-path').text().replace("hdfs://127.0.0.1:9000", "");
        } else if (arg === 2){
            isFolder = $("#filePath_1").val().replace("hdfs://127.0.0.1:9000","");
        }
        console.log("Upload_Path: " + isFolder);
        if (isFolder !== ""){
            console.log("Folder");
            $('#folder_btn').attr("data-path", "Folder");
        }
        else{
            console.log("Root");
            $('#folder_btn').attr("data-path", "Root");
        }
        $('#MkdirModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var path = button.data('path');
            var modal = $(this);
            if (path === "Root"){
                modal.find('.modal-body span').html("/");
            }
            else {
                modal.find('.modal-body span').html(isFolder);
            }
        });
    }

    //创建文件夹关闭事件
    $('#MkdirModal').on('hidden.bs.modal', function () {
        console.log("Close the mkdir modal");
        $('#folder-path').html("/");
    });

    //创建文件夹
    function createFolder(f_name) {
        console.log(f_name);
        var folder_parent = f_name;
        // var folder_parent = $('#filePath_1').val();
        var folder_name = $('#folder-name').val();
        console.log("F:" + folder_name);
        if (folder_parent !== ""){
            folder_name = folder_parent.replace("hdfs://127.0.0.1:9000/", "") + "/" + folder_name;
        }
        if (folder_name === $('#username').text()){
            swal({
                title: "创建文件夹失败!",
                text: "文件夹名字和用户名相同!",
                type: "error",
                confirmButtonText: "关闭"
            }, function (bool) {
                swal.close();
                $('#folder-name').val("");
            })
        } else {
            console.log("Folder Name: " + folder_name);
            $.ajax({
                url: "create_folder",
                data: "folder_name=" + folder_name,
                success: function (data) {
                    console.log(data);
                    $("#MkdirModal").hide();
                    $(".iziModal-overlay").hide();
                    success_result("创建文件夹", function () {});
                },
                error: function (xhr, status, err) {
                    fail_result("请求服务器", function () {});
                }
            });
        }

    }

    //删除文件夹
    function deleteDir(path) {
        var r = $('#treeview12').treeview('getSelected');
        console.log(r);
        console.log(path);
        r = r.filter(function (items) {
            if (items['IsEmpty'] === true) {
                return items
            }
            if (items['type'] === "dir"){
                return items
            }
        });
        if (r.length === 0) {
            alert("没有选中任何文件夹")
        }
        else {
            swal({
                title: "提示",
                text: "你将删除该文件",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false
            },function(isConfirm){
                if (isConfirm) {
                    var folder_path = r[0].path;
                    console.log(folder_path);
                    $.ajax({
                        url: "delete_folder",
                        data: "folder_path=" + folder_path,
                        success: function (data) {
                            console.log(data);
                            success_result("删除文件夹", function () {});
                        },
                        error: function (xhr, status, err) {
                            fail_result("请求服务器", function () {});
                        }
                    });
                } else {
                    swal("操作失败", "你取消了删除！", "error");
                }
            });
        }
    }

    //提交删除返回的结果（失败）
    function fail_result(operation_name, fn) {
        swal({
            title: operation_name + "失败！",
            text: "请重新操作",
            type: "error",
            confirmButtonText: "确定"
        }, function(bool) {
            fn();
        });
    }

    //提交删除返回的结果（成功）
    function success_result(operation_name, fn) {
        swal({
            title: operation_name + "成功!",
            text: "立刻刷新页面查看结果",
            type: "success",
            confirmButtonText: "刷新"
        }, function (bool) {
            if(bool){
                window.location.reload();
            }
        })
    }

    //下载请求成功的结果
    function download_success(operation_name, fn) {
        swal({
            title: operation_name + "成功!",
            text: "立刻刷新页面查看结果",
            type: "success",
            confirmButtonText: "刷新"
        }, function (bool) {
            fn();
        })
    }

    //上传文件
    function upload(isFolder) {
        $("#myModal").modal({
            keyboard: false,
            backdrop: "static"
        });
        var r = $('#treeview12').treeview('getSelected');
        console.log(r);
        r = r.filter(function (items) {
            if (items['IsEmpty'] === true) {
                return items
            }
            if (items['type'] === "dir"){
                return items
            }
        });
        if (r.length === 0) {
            console.log("没有选中任何文件夹");
            init_uploader("/");
        }
        else {
            var upload_path = r[0].path;
            console.log("Upload_Path: " + upload_path);
            // console.log(isFolder);
            // if (isFolder === "Folder"){
            //     console.log("Folder");
            init_uploader(upload_path);
            // }
        }
    }

    //复制文件
    function copyFile() {
        swal({
            title: "复制文件失败!",
            text: "HDFS不支持文件复制功能, 暂无解决办法",
            type: "error",
            confirmButtonText: "确定"
        }, function(bool) {
            swal.close();
        });
    }


    //重命名文件名弹窗
    function renameFileModal() {
        var folder_name = $('#filePath').val();
        $('#RenameModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var modal = $(this);
            modal.find('.modal-body-rename span').html(folder_name);
            var folder_name_array = folder_name.split('/');
            var filename_suffix_array = folder_name_array.pop().split(".");
            console.log(folder_name_array);
            console.log(filename_suffix_array);
            var suffix = filename_suffix_array[filename_suffix_array.length - 1];
            var f_name = filename_suffix_array[0];
            if (filename_suffix_array.length > 2) {
                var temp = filename_suffix_array.pop();
                f_name = filename_suffix_array.join(".");
                console.log(f_name);
            }
            var t = folder_name_array.join("/");
            if (t === ""){
                t = "/";
            }
            modal.find('#rename_folder_path').val(t);
            modal.find('#rename_file_name').val(f_name);
            modal.find('#rename_file_suffix').val(suffix)
        })
    }

    //重命名文件
    function renameFile(op) {
        var file_prefix_path = $('#rename_folder_path').val();
        var file_name = $('#rename_file_name').val();
        var file_suffix = $('#rename_file_suffix').val();
        var fullpath = file_prefix_path + "/" + file_name + "." + file_suffix;

        console.log(op);
        console.log(fullpath);

        if (op.search(file_name) !== -1 ){
            swal({
                title: "重命名文件失败！",
                text: "新文件名与原文件名相同",
                type: "error",
                confirmButtonText: "确定"
            }, function(bool) {
                swal.close();
            });
        } else {
            swal({
                title: "提示",
                text: "你将重命名该文件",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false
            },function(isConfirm){
                if (isConfirm) {
                    $.ajax({
                        url: "rename_folder",
                        data: "oldPath=" + op + "&newPath=" + fullpath,
                        success: function (data) {
                            console.log(data);
                            success_result("重命名文件", function () {});
                        },
                        error: function (xhr, status, err) {
                            fail_result("请求服务器", function () {});
                        }
                    });
                } else {
                    swal("操作失败", "你取消了删除！", "error");
                }
            });
        }
    }

</script>
</body>
</html>